<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
    <meta name="author" content="Coderthemes">

    <link rel="stylesheet" href="/adminstatic/base/base.css"/>
    <script src="/adminstatic/base/baseCss.js"></script>

    <style type="text/css">
        html, body {
            background: #fff;
        }

        .layui-input-block {
            margin-left: 0;
        }
    </style>
</head>

<body class="fixed-left">

<!-- Begin page -->
<div id="wrapper" style="overflow: auto;">

    <div class="container">
        <div class="panel panel-default" style="box-shadow: none">
            <div class="panel-body">
                <form class="layui-form" action="">
                    <div id="inputForm" class="form-horizontal">
                        <div class="row" style="padding:0 20px">
                            <div class="form-group">
                                <div class="col-md-12">
                                    <label for="title"><small class="notNullFlag">*</small> 类型</label>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <label>
                                                <select id="category" name="category" lay-verify="required"
                                                        lay-filter="category">
                                                    <option value="企业资讯">企业资讯</option>
                                                    <option value="展会活动">展会活动</option>
                                                </select>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-12">
                                    <label for="title"><small class="notNullFlag">*</small> 标题</label>
                                    <input class="form-control" type="text" id="title" name="title"
                                           value="" required>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-md-12">
                                    <label for="editor"><small class="notNullFlag">*</small> 内容</label>
                                    <textarea id="editor" name="editor" style="width:100%;height:200px;"></textarea>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <div class="col-xs-12 col-md-4 ">
                                    <label style="width: 100%;"><small class="notNullFlag">*</small> 缩略图</label>
                                    <div class="layui-input-inline layui-btn-container"
                                         style="width: auto;float: unset;">
                                        <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                                            <i class="layui-icon">&#xe67c;</i>上传图片
                                        </button>
                                    </div>
                                </div>

                            </div>

                            <div class="layui-input-inline" id="avatar-preview" style="padding-left: 12px;">
                                <!--                        <div class="img-item">-->
                                <!--                            <img style="width: 100%;height: 100%;" src="https://sentsin.gitee.io/res/images/demo/layer.png">-->
                                <!--                            <div class="img-tag">查看图片</div>-->
                                <!--                        </div>-->
                            </div>


                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div id="actions">
            <button type="button" class="layui-btn layui-btn-normal" id="submitBtn">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="closeIframe()">取消</button>
        </div>
    </div><!-- panel-body -->
</div> <!-- panel -->

</div> <!-- container -->

</div>
<!-- END wrapper -->

<script src="/adminstatic/base/base.js"></script>
<script type="text/javascript">
    var contentHtml;

    var category_name;//类型
    var form;
    layui.use('form', function () {
        form = layui.form;
        category_name = $("#category option:selected").val();

        form.on('select(category)', function (data) {
            //1:拿到select对象：
            category_name = $("#category option:selected").val();
        });
    });


    ckeditor();

    //上传图片
    uploadImg('#LAY_avatarUpload', '/admin/upload/news/addFile', '#avatar-preview')

    //删除图片
    function deleteImg(that) {
        var $this = $(that);
        $this[0].parentNode.remove()
    }

    $("#submitBtn").click(function () {
        var img = $(".img-item img").attr('src')
        var content = CKEDITOR.instances.editor.getData();
        console.log(content, img)

        var title = $("input[name='title']").val();
        if (!vaildeParam(title)) {
            layer.msg("请输入标题", {icon: 5});
            return;
        }
        if (!vaildeParam(content)) {
            layer.msg("请输入内容", {icon: 5});
            return;
        }

        if (!vaildeParam(img)) {
            layer.msg("请添加缩略图", {icon: 5});
            return;
        }


        var api = '/admin/newsActivities/addNewsActivities';
        var data = {
            "category_name": category_name,
            "title": title,
            "img": img,
            "content": content,
        }

        postJSON(api, data, function (res) {
            cleanSuccess(res)
        })

    })

</script>


</body>
</html>